package top.zk123.chain.util;


import com.alibaba.fastjson.JSONObject;

import java.io.*;

/**
 * JSON 工具类
 *
 * @author Ke Zhang
 * @since 2.0
 */
public class JSONUtil {
    /**
     * File 转 JSON 字符串
     *
     * @param filePath 文件路径
     * @return String
     */
    public static String File2JSON(String filePath) {
        File file = new File(filePath);
        StringBuilder builder = new StringBuilder();
        try {
            FileInputStream is = new FileInputStream(file);
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return builder.toString();
    }
    public static JSONObject String2JSON(String str) {
        JSONObject jsonObject = new JSONObject();
        jsonObject = JSONObject.parseObject(str);
        return jsonObject;
    }
}
